package com.tuanzi.loan.business.service.statistics.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuanzi.loan.business.repository.statistics.NginxLinkStatRepository;
import com.tuanzi.loan.business.service.statistics.NginxLinkStatService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.statistics.NginxLinkStatRequest;
import com.tuanzi.loan.vo.response.statistics.ActivityAverageJoinStatResponse;
import com.tuanzi.loan.vo.response.statistics.NginxLinkStatResponse;

@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class NginxLinkStatServiceImpl implements NginxLinkStatService{
	
	@Autowired
	private NginxLinkStatRepository nginxLinkStatRepository;
	
	public String getExcel(NginxLinkStatRequest searchRequest) {
		List<NginxLinkStatResponse> allList = nginxLinkStatRepository.getAllList(searchRequest);
		
    	StringBuffer sf = new StringBuffer();
		sf.append("时间,平台,请求方式,URL,UV,PV\r\n");
		if(allList != null) {
			for(NginxLinkStatResponse response : allList) {
				sf.append(response.getCdate()+",");
				sf.append(response.getPlatform()+",");
				sf.append(response.getRequestMethod()+",");
				sf.append(response.getUrl()+",");
				sf.append(response.getUv()+",");
				sf.append(response.getPv());
				sf.append("\r\n");
			}
		}
    	
    	return sf.toString();
    }
	
	public Page<NginxLinkStatResponse> list(PageSearcher<NginxLinkStatRequest> pageSearcher) {
		// 参与统计
		Page<NginxLinkStatResponse> listPage = nginxLinkStatRepository
				.getlistPageByActivityJoin(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
		return listPage;
	}
	
	public NginxLinkStatResponse getAllListDataSum(NginxLinkStatRequest searchRequest) {
		return nginxLinkStatRepository.getAllListDataSum(searchRequest);
	}
	
	
}

























